<?php

/**
 * 首页
 * User: tsang
 * Date: 2017/9/14
 * Time: 20:11
 */

namespace app\mobile\controller;
use think\Controller;

class Index extends Base
{
    /*
    *	构造函数
    */
    function __construct(){
        parent::__construct();
    }

    /*
     * 首页
     */
    public function index()
    {
        return $this->fetch('Public/index');//加载iframe
    }

    public function zindex()
    {
        //首页动态文章
        $dynamic_result = db('dynamic')->order('id desc')->find();
        $dynamic_result['url'] = url('Dynamic/detail',array('id'=>$dynamic_result['id']));;

        $publicityList = [];
        $noticeList = [];
        $policyList = [];

        //公示
        $whereb['over_time'] = ['>',time()];
        $whereb['is_display'] = 1;
        $publicityList = db('publicity')
            ->field('id,title,department,over_time,create_time')
            ->where($whereb)
            ->order('create_time','desc')
            ->limit(3)
            ->select();
        $publicityList = $this->return_date($publicityList);

        //通知
        $wherec['is_display'] = 1;
        $noticeList = db('notice')
            ->field('id,title,department,create_time')
            ->where($wherec)
            ->order('create_time','desc')
            ->limit(3)
            ->select();
        $noticeList = $this->return_date($noticeList);

        //政策文件
        $whered['is_display'] = 1;
        $policyList = db('policy')
            ->field('id,department,title,create_time')
            ->where($whered)
            ->order('create_time','desc')
            ->limit(3)
            ->select();
        $policyList = $this->return_date($policyList);

        $this->assign('dynamic_result',$dynamic_result);
        $this->assign('publicityList', $publicityList);
        $this->assign('noticeList', $noticeList);
        $this->assign('policyList', $policyList);
        return $this->fetch();
    }

    public function return_date($array){
        if(empty($array))return $array;
        foreach ($array as $key => &$value) {
            $value['create_time'] = date('Y-m-d',$value['create_time']);
        }
        return $array;
    }


}